package com.qf.t1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

/*
杨威
2021/9/3
20:55
*/
public class TestSelect {
    public static void main(String[] args) throws Exception{
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        String username = scanner.nextLine();
        System.out.println("请输入密码");
        String password = scanner.nextLine();
        Class.forName("com.mysql.jdbc.Driver");
        Connection root = DriverManager.getConnection("jdbc:mysql:///schools?useSSL=false&characterEncoding=utf-8", "root", "1234");
        PreparedStatement preparedStatement = root.prepareStatement("select * from user where username=? and password=?;");
        System.out.println("preparedStatement = " + preparedStatement);
        preparedStatement.setString(1, username);
        preparedStatement.setString(2, password);
        System.out.println("preparedStatement = " + preparedStatement);
        ResultSet resultSet = preparedStatement.executeQuery();
        if(resultSet.next()){
            System.out.println("登录成功");
        }else{
            System.out.println("登陆失败");
        }

    }
}
